package cn.ekuma.epos.datalogic.define.dao;

import org.jumpmind.symmetric.model.NodeGroupLinkAction;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.Session;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;

import cn.ekuma.data.dao.BaseDAO;
import cn.ekuma.epos.symmetricds.AppConfig;
import cn.ekuma.epos.symmetricds.bean.NodeGroupLink;

public class NodeGroupLinkDAO extends BaseDAO<NodeGroupLink> {

	public NodeGroupLinkDAO(I_Session s) {
		super(s);
		
	}

	@Override
	public NodeGroupLink readValues(DataRead dr,NodeGroupLink obj) throws BasicException {
		if(obj==null)
			obj=new NodeGroupLink();
		obj.setSourceNodeGroupId(dr.getString(1));
		obj.setTargetNodeGroupId(dr.getString(2));
		obj.setDataEventAction(NodeGroupLinkAction.fromCode(dr.getString(3)));
		return obj;
	}

	@Override
	public TableDefinition getTable() {
		return new TableDefinition(s,
				AppConfig.getAppProperty(AppConfig.TABLE_PREFIX)+"_"+"node_group_link",
                new Field[]{
                   new Field("source_node_group_id",Datas.STRING, Formats.STRING),
                   new Field("target_node_group_id",Datas.STRING, Formats.STRING),
                   new Field("data_event_action",Datas.STRING, Formats.STRING)
                 },
                new int[]{0,1}
                );
	}
	
	/**
	 * <table name="node_group_link" description="A source node_group sends its data updates to a target NodeGroup using a pull, push, or custom technique.">
        <column name="source_node_group_id" type="VARCHAR" size="50" required="true" primaryKey="true" description="The node group where data changes should be captured." />
        <column name="target_node_group_id" type="VARCHAR" size="50" required="true" primaryKey="true" description="The node group where data changes will be sent." />
        <column name="data_event_action" type="CHAR" size="1" default="W" required="true" description="The notification scheme used to send data changes to the target node group. (P = Push, W = Wait for Pull) " />
    </table>
	 */


	@Override
	public Class getSuportClass() {
		return NodeGroupLink.class;
	}

	@Override
	public void writeInsertValues(DataWrite dp, NodeGroupLink obj)
			throws BasicException {
		dp.setString(1,obj.getSourceNodeGroupId());
		dp.setString(2,obj.getTargetNodeGroupId());
		dp.setString(3,obj.getDataEventAction().name());
	}

}
